﻿using CemsTransfer.BUS;
using CemsTransfer.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace CemsTransfer.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        public LoginController()
        {

        }

        [HttpPost]
        [Route("Login")]
        public ResponseMessage Login(User user)
        {
            ResponseMessage message = new ResponseMessage();
            try
            {
                string uname = AppSettingsHelper.Configuration["UserName"];
                string upwd = AppSettingsHelper.Configuration["UserPwd"];
                if (user.username == uname && upwd == user.password)
                {
                    message.errcode = 0;
                    message.total = 1;
                }
                else
                {
                    message.errcode = 1;
                    message.errmsg = "用户名或密码错误";
                    message.total = 0;
                }
            }
            catch (Exception ex)
            {
                message.errcode = 1;
                message.errmsg = "登录异常";
                message.total = 0;
            }
            return message;
        }
    }
}
